﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    class AnimatedObject : Objeto2D
    {


        public Dictionary<String, AnimationStructure> listaAnimations;

        public struct AnimationStructure
        {
            public int frameWidth;
            public int frameHeight;
            public int frameCount;
            public int framePerSecond;
            public int X;
            public int Y;
        }


        AnimationStructure animation;

        int frame;
        
        public AnimatedObject(Texture2D texture, int width, int height)
            : base(texture)
        {
            listaAnimations = new Dictionary<String, AnimationStructure>();

            frame = 4;

            retanguloDeCorte = new Rectangle(0, 0, width, height);
            vetorOrigem = new Vector2(width / 2, height / 2);

            AnimationStructure animationDefault = new AnimationStructure();
            animationDefault.frameCount = 1;
            animationDefault.frameWidth = width;
            animationDefault.frameHeight = height;
            animationDefault.framePerSecond = 1;
            animationDefault.X = 0;
            animationDefault.Y = 0;
            listaAnimations.Add("default", animationDefault);

            ChangeAnimation("default");

        }

        public void ChangeAnimation(String nome)
        {
            animation = listaAnimations[nome];
        }

        public virtual void Update(GameTime gameTime)
        {
            frame = (int)(gameTime.TotalGameTime.TotalSeconds * animation.framePerSecond) % animation.frameCount;

            retanguloDeCorte = new Rectangle(
                animation.X + frame * animation.frameWidth,
                animation.Y,
                animation.frameWidth,
                animation.frameHeight);
        }

    }
}
